#! /usr/bin/env python
# -*- coding: utf-8 -*-


import unittest
from kmp import KmpMatch


class MyTestCase(unittest.TestCase, ):
    def setUp(self):
        print("start test '%s'" % self.__class__.__name__)
        self.kmp = KmpMatch()

    def tearDown(self):
        print("end test '%s' \n" % self.__class__.__name__)

    def test_max_pre_len(self):
        self.assertEqual( self.kmp.max_pre_len('abc'),          0)
        self.assertEqual( self.kmp.max_pre_len('aba'),          1)
        self.assertEqual( self.kmp.max_pre_len('abab'),         2)
        self.assertEqual( self.kmp.max_pre_len('abab_aba'),     3)
        self.assertEqual( self.kmp.max_pre_len('abcd__abcd'),   4)
        self.assertEqual( self.kmp.max_pre_len('abcd__abcd_'),  5)
        self.assertEqual( self.kmp.max_pre_len('abcd__abcd__'), 6)
        self.assertEqual( self.kmp.max_pre_len('abcd__zabcd__'), 6)

    def test_kmp_match(self):
        r = self.kmp.kmp_match('abcduvwxzyzefgh', 'ef')
        self.assertEqual(r, 11)

        r = self.kmp.kmp_match('abcduvwxzyzefgh', 'ab')
        self.assertEqual(r, 0)

        r = self.kmp.kmp_match('abcduvwxzyzefgh', 'bcdu')
        self.assertEqual(r, 1)

        r = self.kmp.kmp_match('abcdabddabc', 'abd')
        self.assertEqual(r, 4)

    # def test_1(self):
    #     self.assertEqual(a, b)


# def suite():
#     all_suite = unittest.TestSuite()

#     suite_xml = unittest.TestLoader().loadTestsFromTestCase(XmlTest)
#     suite_dom = unittest.TestLoader().loadTestsFromTestCase(DomTest)

#     # all_suite.addTest(suite_dom)
#     # all_suite.addTest(suite_xml)
#     all_suite.addTests([suite_dom, suite_xml])

#     return all_suite


if __name__ == "__main__":
    unittest.main()
    # unittest.TextTestRunner(verbosity=2).run(suite())
